package cn.edu.ctbu.dp2.service;

import cn.edu.ctbu.dp2.dao.TeacherRepository;
import cn.edu.ctbu.dp2.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;
@Service
public class TeacherService {

    @Autowired
    public TeacherRepository teacherRepository;

      /**
       * 读所有的学生数据
       * @return List Teacher
       */
      public List<Teacher> getAll() {
          return teacherRepository.findAll();
      }

    /**
     * 新增老师
     * @param teacher 对象
     */
    public Teacher add(Teacher teacher){

        return teacherRepository.save(teacher);
    }

    /**
     * 更新学生
     * @param teacher 对象
     */
    public Teacher update(Teacher teacher){
         return teacherRepository.save(teacher);
    }
/**
     * 删除数据
     * @param id 根据id删除数据
     */
    public void delete(Integer id){
        teacherRepository.deleteById(id);
    }

    public Teacher findById(int id){
        return teacherRepository.findById(id).get();
    }

  }



